#include "Configuration.h"

using namespace pong;

Configuration::Configuration(const Ogre::String& folder, Ogre::Root* const root) 
	: configFolder(folder), ogreRoot(root)
{
	if (!ogreRoot->showConfigDialog()) {
		//Open up the video settings
		Ogre::ConfigFile videoConfig;
		videoConfig.loadDirect(configFolder + "/video.cfg");

		//Look for the renderSystem....
		Ogre::RenderSystem* renderer(ogreRoot->getRenderSystemByName(videoConfig.getSetting("System")));
		//If it doesn't exist or something, choose a default one
		if (renderer == NULL) {
			/*If there's no renderer available, then there's really
				nothing we can do, so we just choose nothing and let OGRE
				except later*/
			renderer = defaultRenderer();
		}
		ogreRoot->setRenderSystem(renderer);

		//Now, load as many options as possible from the config
		for (Ogre::ConfigFile::SettingsIterator itr(videoConfig.getSettingsIterator(renderer->getName()));
			 itr.hasMoreElements(); itr.moveNext()
		    )
		{
			videoSettings.insert(std::make_pair(itr.peekNextKey(), itr.peekNextValue()));
		}
	}
	//That's it; all we do here is load configs. They're applied later
}